#Replication Code File for Online Appendix of "Does Social Media Promote Civic Activism? A Field Experiment with a Civic Campaign"

rm(list=ls())

install.packages("stargazer", dependencies=TRUE)
install.packages("lmtest")
install.packages("nnet")
install.packages("AER")
install.packages("ri")
install.packages("foreign")
install.packages("plyr")
install.packages("randomizr")
install.packages("xtable")
install.packages("tidyverse")
install.packages("estimatr")
install.packages("readstata13")
install.packages("DeclareDesign")
install.packages("DesignLibrary")

sIOA <- sessionInfo()
sIOA

library(stargazer) 
library(lmtest)  
library(nnet)     
library(AER)  
library(ri)         # load the RI package 
library(foreign) 
library(plyr)
library(randomizr)
library(xtable)
library(tidyverse)
library(estimatr)
library(readstata13)
library(DeclareDesign)
library(DesignLibrary)

set.seed(1234567) 
options(scipen=999)

#setwd("") # set working directory

#Appendix A

data <- read.dta13("data_fb.dta")

data$uni[data$edu_1==1] <- 1
data$uni[data$edu_2==1] <- 0
data$uni[data$edu_3==1] <- 0
data$uni[data$edu_4==1] <- 0
data$uni[data$edu_5==1] <- 0

data$status_per[data$status_1==1] <- 1
data$status_per[data$status_2==1] <- 1
data$status_per[data$status_3==1] <- 0
data$status_per[data$status_4==1] <- 0
data$status_per[data$status_5==1] <- 0

data$fbnews[data$fblike==1] <- 1
data$fbnews[data$newsletter==1] <- 0

subsample_var2<-subset(data, !is.na(fbnews), select=c(assignment, stream, fbnews, townpoplog, age_re, sex_2, uni, status_per, friends_re, fbfriends_re, frequency_fb,  news_2, news_3, scale_trust, role_2, role_3, knowledgescale, nature_re, danger, adventure, pleasure, ability, civic_re, environment_act_2, vote_re))

Z<-subsample_var2$fbnews

X<- as.matrix(subsample_var2[,4:25])

table(Z)

nsims <- 5000 

set.seed(1234567) 

fstatstore <- rep(NA,nsims)

for (i in 1:nsims) {
  fstatstore[i] <- summary(lm(simple_ra(N=331) ~ X))$fstatistic[1]
}

fstat <- summary(lm(Z~X))$fstatistic[1]

mean(fstat <= fstatstore) #0.6222

lm_fit1 <- lm(Z~X)

sum4 <- coeftest(lm_fit1) 


pdf(paste("balance_compliance.pdf"),w=6,h=5)
hist(fstatstore,breaks = 100, main = paste("Sampling distribution of simulated f-statistics"), xlab=("f-statistic"))
abline(v=fstat, col="red", lwd=3)
dev.off()



#Appendix C


#Figure A2


#small effect .25 sd

possible.ns <- seq(from=100, to=900, by=10)
powers <- rep(NA, length(possible.ns))
alpha <- 0.05
set.seed(12345678)
sims <- 5000
for (j in 1:length(possible.ns)){
  N <- possible.ns[j]
  
  significant.experiments <- rep(NA, sims)
  
  for (i in 1:sims){                         # "Effect" of the covariate
    
    ## Control Outcome as a function of covariate and error
    Y0 <- rnorm(n=N, mean=0, sd=1) 
    
    tau <- 0.25
    Y1 <- Y0 + tau
    Z.sim <- rbinom(n=N, size=1, prob=.46)
    Y.sim <- Y1*Z.sim + Y0*(1-Z.sim)
    fit.sim <- lm(Y.sim ~ Z.sim)
    
    
    ## extract p-values and calculate significance ##
    p.value <- summary(fit.sim)$coefficients[2,4]
    
    significant.experiments[i] <- (p.value <= alpha)  }
  
  powers[j] <- mean(significant.experiments)
}



#moderately large effect .50 sd

possible.ns <- seq(from=100, to=900, by=10)
powers2 <- rep(NA, length(possible.ns))
alpha <- 0.05
set.seed(1234567)
sims <- 5000
for (j in 1:length(possible.ns)){
  N <- possible.ns[j]
  
  significant.experiments <- rep(NA, sims)
  
  for (i in 1:sims){                         # "Effect" of the covariate
    
    ## Control Outcome 
    Y0 <- rnorm(n=N, mean=0, sd=1) 
    
    tau <- 0.50
    Y1 <- Y0 + tau
    Z.sim <- rbinom(n=N, size=1, prob=.46)
    Y.sim <- Y1*Z.sim + Y0*(1-Z.sim)
    fit.sim <- lm(Y.sim ~ Z.sim)
    
    
    ## extract p-values and calculate significance ##
    p.value2 <- summary(fit.sim)$coefficients[2,4]
    
    significant.experiments[i] <- (p.value2 <= alpha)  }
  
  powers2[j] <- mean(significant.experiments)
}


#Figure A2

pdf(file="power1.pdf", width=7, height=5.5)
plot(possible.ns, powers, ylim=c(0,1), xlim=c(100, 900), xlab=("sample sizes"), ylab=("simulated power"))
points(possible.ns, powers2, col="red")

dev.off()



#Appendix C: Table A1

tab_power<-NA

tab_power <- data.frame(c(rep("Design1",1), rep("Design2",1), rep("Design3",1)))
tab_power$effectsize<- NA
tab_power$dnews<- NA
tab_power$dfacebook <- NA
tab_power$power <- NA

colnames(tab_power) <- c("Assumption", "d newsletter", "d Facebook","Power Fb vs Control", "Power Nl vs Control")
dim(tab_power)

tab_power

tab_power[1,2]<-.25
tab_power[1,3]<-.25
tab_power[2,2]<-.50
tab_power[2,3]<-.50
tab_power[3,2]<-.25
tab_power[3,3]<-.50

design1<-multi_arm_designer(N = 559, m_arms = 3, outcome_means=c(0, 0.25, 0.25), sd_i=1)

design2<-multi_arm_designer(N = 559, m_arms = 3, outcome_means=c(0, 0.50, 0.50), sd_i=1)

design3<-multi_arm_designer(N = 559, m_arms = 3, outcome_means=c(0, 0.25, 0.50), sd_i=1)

set.seed(1234567)

results<-diagnose_design(design1, design2, design3, sims=5000)

tab_power[1,4]<-round(results$diagnosands[1,8], digits=2)
tab_power[1,5]<-round(results$diagnosands[2,8] , digits=2)
tab_power[2,4]<-round(results$diagnosands[4,8], digits=2)
tab_power[2,5]<-round(results$diagnosands[5,8], digits=2)
tab_power[3,4]<-round(results$diagnosands[7,8], digits=2)
tab_power[3,5]<-round(results$diagnosands[8,8], digits=2)

xtable(tab_power)


#Appendix F: Attrition

#Missingness in the outcome variable as a function of treatment assignment

#Wave 2

Z<-data$assignment

data$missing[data$a012==0] <-1
data$missing[data$a012==1] <-0

X <-data$missing

table(Z)
table(X)

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

nsims <- 5000 

set.seed(1234567) 

loglikstore <- rep(NA,nsims)

for (i in 1:nsims) {
  loglikstore[i] <- summary(multinom(simple_ra(N=884,num_arms=3)~X))$deviance/-2 
}

loglik <- summary(multinom(Z~X))$deviance/-2

mean(loglik<=loglikstore) #p-value 0.5062


#Figure A3

pdf(paste("attrition2.pdf"),w=6,h=5)
hist(loglikstore, breaks = 100, main = paste("Sampling distribution of simulated log-likelihoods"), xlab=("simulated and observed log-likelihood"))
abline(v=loglik, col="red", lwd=3)
dev.off() 


#large sample f-test

set.seed(1234567)

blocks<-data$stream

table(blocks, assignment)

block_m_each <- rbind(c(177,163, 187),
                   c(133, 109, 115))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

large_sample<-lm_robust(X~factor(Z), weight = 1/prob_obs)

f_stat<-summary(large_sample)$fstatistic

pvalue<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2) 

pvalue #0.78 


#Appendix G: Balance


data <- read.dta13("data_fb.dta")

data$uni[data$edu_1==1] <- 1
data$uni[data$edu_2==1] <- 0
data$uni[data$edu_3==1] <- 0
data$uni[data$edu_4==1] <- 0
data$uni[data$edu_5==1] <- 0


data$status_per[data$status_1==1] <- 1
data$status_per[data$status_2==1] <- 1
data$status_per[data$status_3==1] <- 0
data$status_per[data$status_4==1] <- 0
data$status_per[data$status_5==1] <- 0

subsample_var<-subset(data, select=c(assignment, stream, townpoplog, age_re, sex_2, uni, status_per, friends_re, fbfriends_re, frequency_fb,  news_2, news_3, scale_trust, role_2, role_3, knowledgescale, nature_re, danger, adventure, pleasure, ability, civic_re, environment_act_2, vote_re))


#Balance Check

Z<-subsample_var$assignment
table(Z)
X<- as.matrix(subsample_var[,3:24])

nsims <- 5000 #Set number of simulations. 

set.seed(1234567) 

loglikstore <- rep(NA,nsims)

for (i in 1:nsims) {
  loglikstore[i] <- summary(multinom(simple_ra(N=884, num_arms = 3)~X))$deviance/-2 
}

loglik <- summary(multinom(Z~X))$deviance/-2

mean(loglik <= loglikstore) #p-value 0.3222

#Figure A4

pdf(paste("plot_balance_ri2.pdf"),w=6,h=5)
hist(loglikstore,  breaks = 100, main = paste("Sampling distribution of simulated log-likelihoods"), xlab=("simulated and observed log-likelihood"))
abline(v=loglik, col="red", lwd=3)
dev.off()



#Balance Table

tab_balance<-NA

tab_balance <- data.frame(c(rep("Townpop",1), rep("Age", 1), rep("Male", 1),  rep("Uni", 1), rep("Well-Off", 1), rep("Number friends", 1),  rep("Number fb friends", 1),
                            rep("Freq fbook use", 1), rep("News from print", 1), rep("News from social media", 1), rep("Trust institutions", 1), rep("Civil society equal role", 1), rep("Civil society secondary role", 1), rep("Knowledge environment", 1),
                            rep("Love nature", 1), rep("Like danger", 1), rep("Seek adventure", 1), rep("Seek pleasure", 1), rep("Showcase ability", 1), rep("Civic activism", 1), rep("Environmental activism", 1),  rep("Freq of voting", 1)))
tab_balance$meanc<- NA
tab_balance$meanemail <- NA
tab_balance$meanFB <- NA
tab_balance$p <- NA
colnames(tab_balance) <- c("Covariate", "Mean Control", "Mean Email", "Mean Facebook", "P-Value F-test")
dim(tab_balance)


Z<-subsample_var$assignment

subsample_var$blocks[subsample_var$stream=="representative"] <-0
subsample_var$blocks[subsample_var$stream=="activists"] <-1

blocks<-subsample_var$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

block_m_each <- rbind(c(177, 163, 187),
                      c(133, 109, 115))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

#Townpop

tab_balance[1,2]<-round(mean(subsample_var$townpoplog[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[1,3]<-round(mean(subsample_var$townpoplog[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[1,4]<-round(mean(subsample_var$townpoplog[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$townpoplog~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[1,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Age

tab_balance[2,2]<-round(mean(subsample_var$age_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[2,3]<-round(mean(subsample_var$age_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[2,4]<-round(mean(subsample_var$age_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$age_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[2,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#Sex

tab_balance[3,2]<-round(mean(subsample_var$sex_2[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[3,3]<-round(mean(subsample_var$sex_2[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[3,4]<-round(mean(subsample_var$sex_2[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$sex_2~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[3,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Uni
tab_balance[4,2]<-round(mean(subsample_var$uni[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[4,3]<-round(mean(subsample_var$uni[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[4,4]<-round(mean(subsample_var$uni[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$uni~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[4,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Social status
tab_balance[5,2]<-round(mean(subsample_var$status_per[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[5,3]<-round(mean(subsample_var$status_per[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[5,4]<-round(mean(subsample_var$status_per[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$status_per~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[5,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Number of friends
tab_balance[6,2]<-round(mean(subsample_var$friends_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[6,3]<-round(mean(subsample_var$friends_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[6,4]<-round(mean(subsample_var$friends_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$friends_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[6,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Number of friends
tab_balance[7,2]<-round(mean(subsample_var$fbfriends_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[7,3]<-round(mean(subsample_var$fbfriends_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[7,4]<-round(mean(subsample_var$fbfriends_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$fbfriends_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[7,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Freq fb use
tab_balance[8,2]<-round(mean(subsample_var$frequency_fb[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[8,3]<-round(mean(subsample_var$frequency_fb[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[8,4]<-round(mean(subsample_var$frequency_fb[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$frequency_fb~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[8,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#News print
tab_balance[9,2]<-round(mean(subsample_var$news_2[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[9,3]<-round(mean(subsample_var$news_2[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[9,4]<-round(mean(subsample_var$news_2[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$news_2~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[9,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#News social media

tab_balance[10,2]<-round(mean(subsample_var$news_3[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[10,3]<-round(mean(subsample_var$news_3[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[10,4]<-round(mean(subsample_var$news_3[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$news_3~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[10,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#Trust scale
tab_balance[11,2]<-round(mean(subsample_var$scale_trust[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[11,3]<-round(mean(subsample_var$scale_trust[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[11,4]<-round(mean(subsample_var$scale_trust[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$scale_trust~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[11,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Equal role
tab_balance[12,2]<-round(mean(subsample_var$role_2[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[12,3]<-round(mean(subsample_var$role_2[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[12,4]<-round(mean(subsample_var$role_2[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$role_2~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[12,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Secondary role
tab_balance[13,2]<-round(mean(subsample_var$role_3[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[13,3]<-round(mean(subsample_var$role_3[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[13,4]<-round(mean(subsample_var$role_3[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$role_3~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[13,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Knowledge scale
tab_balance[14,2]<-round(mean(subsample_var$knowledgescale[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[14,3]<-round(mean(subsample_var$knowledgescale[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[14,4]<-round(mean(subsample_var$knowledgescale[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$knowledgescale~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[14,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Nature re
tab_balance[15,2]<-round(mean(subsample_var$nature_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[15,3]<-round(mean(subsample_var$nature_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[15,4]<-round(mean(subsample_var$nature_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$nature_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[15,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Danger
tab_balance[16,2]<-round(mean(subsample_var$danger[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[16,3]<-round(mean(subsample_var$danger[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[16,4]<-round(mean(subsample_var$danger[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$danger~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[16,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Adventure
tab_balance[17,2]<-round(mean(subsample_var$adventure[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[17,3]<-round(mean(subsample_var$adventure[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[17,4]<-round(mean(subsample_var$adventure[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$adventure~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[17,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Pleasure
tab_balance[18,2]<-round(mean(subsample_var$pleasure[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[18,3]<-round(mean(subsample_var$pleasure[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[18,4]<-round(mean(subsample_var$pleasure[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$pleasure~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[18,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Ability
tab_balance[19,2]<-round(mean(subsample_var$ability[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[19,3]<-round(mean(subsample_var$ability[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[19,4]<-round(mean(subsample_var$ability[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$ability~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[19,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#Civic activism
tab_balance[20,2]<-round(mean(subsample_var$civic_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[20,3]<-round(mean(subsample_var$civic_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[20,4]<-round(mean(subsample_var$civic_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$civic_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[20,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)


#environmental activism
tab_balance[21,2]<-round(mean(subsample_var$environment_act_2[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[21,3]<-round(mean(subsample_var$environment_act_2[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[21,4]<-round(mean(subsample_var$environment_act_2[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$environment_act_2~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[21,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#vote
tab_balance[22,2]<-round(mean(subsample_var$vote_re[subsample_var$assignment==1], weight=1/prob_obs), digits=2)

tab_balance[22,3]<-round(mean(subsample_var$vote_re[subsample_var$assignment==2], weight=1/prob_obs), digits=2)

tab_balance[22,4]<-round(mean(subsample_var$vote_re[subsample_var$assignment==3], weight=1/prob_obs), digits=2)

f_stat <- summary(lm_robust(subsample_var$vote_re~factor(subsample_var$assignment), weight=1/prob_obs))$fstatistic

tab_balance[22,5]<-round(1 - pf(q = f_stat[1], df1 = f_stat[2], df2 = f_stat[3]), digits=2)

#Table A3
xtable(tab_balance)



#Figure A5

popularity <- read_tsv("fb_likes.tsv")

pdf(paste("post_popularity.pdf"),w=6,h=5)
ggplot(popularity , aes(x=post_number, y=likes)) +
  geom_point(size=2, shape=1)  + ylab("Likes") + ylim(0, 150) + xlab("post number") + scale_x_continuous(breaks=c(0, 10,  20,  30,  40)) + theme_bw() + theme(panel.border = element_blank(), panel.grid.major = element_blank(), panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"))
dev.off() 



#Table A4

subsample <- read.dta13("data_fb.dta")

subsample_var<-subset(subsample, select=c(assignment, fblike, newsletter, role_graph, vote_graph, age, compliance, civic, danger_graph, adventure_graph, scale_trust, natureloving, fbtreat, fbvsnewsletter, stream,  townpoplog, age_re, age_mis, sex_2, sex_3, edu_1, edu_2, edu_3, edu_4, edu_5, status_1, status_2, status_3, status_4, status_5, friends_re, friends_mis, fbfriends_re, fbfriends_mis, frequency_fb, frequency_fb_mis, news_2, news_3, news_4, civic_re, civic_mis, environment_act_2, environment_act_3, vote_re, vote_mis, scale_trust, role_2, role_3, role_4, knowledgescale, nature_re, nature_mis, danger, danger_mis, adventure, adventure_mis, pleasure, pleasure_mis, ability, ability_mis))

subsample_var$uni[subsample_var$edu_1==1] <- 1
subsample_var$uni[subsample_var$edu_2==1] <- 0
subsample_var$uni[subsample_var$edu_3==1] <- 0
subsample_var$uni[subsample_var$edu_4==1] <- 0
subsample_var$uni[subsample_var$edu_5==1] <- 0

subsample_var$status_per[subsample_var$status_1==1] <- 1
subsample_var$status_per[subsample_var$status_2==1] <- 1
subsample_var$status_per[subsample_var$status_3==1] <- 0
subsample_var$status_per[subsample_var$status_4==1] <- 0
subsample_var$status_per[subsample_var$status_5==1] <- 0

subsample_var$blocks[subsample_var$stream=="representative"] <-0
subsample_var$blocks[subsample_var$stream=="activists"] <-1

subsample_var$representative[subsample_var$stream=="representative"] <-1
subsample_var$activist[subsample_var$stream=="activists"] <-1

subsample_var$fbcomply[subsample_var$assignment==2 & subsample_var$compliance==1] <- 1
subsample_var$fbcomply[subsample_var$assignment==2 & subsample_var$compliance==0] <- 0

subsample_var$newslettercomply[subsample_var$assignment==3 & subsample_var$compliance==1] <- 1
subsample_var$newslettercomply[subsample_var$assignment==3 & subsample_var$compliance==0] <- 0

subsample_var$comply4cat[subsample_var$fblike==1] <- "1. fb like"
subsample_var$comply4cat[subsample_var$newsletter==1] <- "3. newsletter sign-up"
subsample_var$comply4cat[subsample_var$assignment==2 & subsample_var$fblike==0] <- "2. fb non-compliers"
subsample_var$comply4cat[subsample_var$assignment==3 & subsample_var$newsletter==0] <- "4. newsletter non-complier"

subsample_var_rep<-subset(subsample_var, !is.na(representative))

subsample_var_rep<-subset(subsample_var_rep, !is.na(comply4cat))

subsample_var_facebook<-subset(subsample_var_rep, !is.na(fbcomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb, news_2, news_3, news_4, scale_trust, role_2, role_3, role_4, knowledgescale, nature_re, danger,  adventure,  pleasure, ability,  civic_re, civic_mis, environment_act_2, environment_act_3, vote_re))
subsample_var_newsletter<-subset(subsample_var_rep, !is.na(newslettercomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb, news_2, news_3, news_4, scale_trust, role_2, role_3, role_4, knowledgescale, nature_re, danger,  adventure,  pleasure, ability, civic_re, civic_mis, environment_act_2, environment_act_3, vote_re))
subsample_var_fb_demo<-subset(subsample_var_rep, !is.na(fbcomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb))
subsample_var_nl_demo<-subset(subsample_var_rep, !is.na(newslettercomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb))
subsample_var_fb_demoplus<-subset(subsample_var_rep, !is.na(fbcomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb, news_2, news_3, news_4, scale_trust, role_2, role_3, role_4, knowledgescale, nature_re, danger,  adventure,  pleasure, ability))
subsample_var_nl_demoplus<-subset(subsample_var_rep, !is.na(newslettercomply), select=c(fbcomply, newslettercomply, townpoplog, age_re, sex_2, sex_3, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb, news_2, news_3, news_4, scale_trust, role_2, role_3, role_4, knowledgescale, nature_re, danger,  adventure,  pleasure, ability))


Y <- subsample_var_fb_demo$fbcomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_fb_demo[,3:13])

lm_fit1 <- lm(Y~X)

sum1 <- coeftest(lm_fit1, vcovHC(lm_fit1, type="HC2"))  


Y <- subsample_var_nl_demo$newslettercomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_nl_demo[,3:13])


lm_fit2 <- lm(Y~ X)

sum2 <- coeftest(lm_fit2, vcovHC(lm_fit2, type="HC2"))  


Y <- subsample_var_fb_demoplus$fbcomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_fb_demoplus[,3:26])

lm_fit3 <- lm(Y~X)

sum3 <- coeftest(lm_fit3, vcovHC(lm_fit3, type="HC2"))  


Y <- subsample_var_nl_demoplus$newslettercomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_nl_demoplus[,3:26])


lm_fit4 <- lm(Y~ X)

sum4 <- coeftest(lm_fit4, vcovHC(lm_fit4, type="HC2"))  


Y <- subsample_var_facebook$fbcomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_facebook[,3:31])

lm_fit5 <- lm(Y~X)

sum5 <- coeftest(lm_fit5, vcovHC(lm_fit5, type="HC2"))  


Y <- subsample_var_newsletter$newslettercomply # define Outcome
table(Y)

X<- as.matrix(subsample_var_newsletter[,3:31])


lm_fit6 <- lm(Y~ X)

sum6 <- coeftest(lm_fit6, vcovHC(lm_fit6, type="HC2"))  


#Produce Table A4

Tablea4<-stargazer(sum1,sum3, sum5, sum2, sum4, sum6,
          type = "latex", title ="", style = "AJPS",
          summary = NULL, out = NULL, out.header = FALSE,
          column.labels = NULL, column.separate = NULL,
          covariate.labels = NULL, dep.var.caption = NULL,
          dep.var.labels = NULL, dep.var.labels.include = TRUE,
          align = FALSE,
          coef = NULL, se = NULL, t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = FALSE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = FALSE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL,
          label = "", model.names = NULL,
          model.numbers = NULL, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("_mis", "Xregion", "Constant", "Xsex_3", "Xedu_5", "status_5", "Xrole_4", "frequency_fb_3", "environment_act_3", "Xnews_4"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = TRUE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#Section 5

subsample2 <- read.dta13("data_fb.dta")


#Recode

subsample2$uni[subsample2$edu_1==1] <- 1
subsample2$uni[subsample2$edu_2==1] <- 0
subsample2$uni[subsample2$edu_3==1] <- 0
subsample2$uni[subsample2$edu_4==1] <- 0
subsample2$uni[subsample2$edu_5==1] <- 0


subsample2$status_per[subsample2$status_1==1] <- 1
subsample2$status_per[subsample2$status_2==1] <- 1
subsample2$status_per[subsample2$status_3==1] <- 0
subsample2$status_per[subsample2$status_4==1] <- 0
subsample2$status_per[subsample2$status_5==1] <- 0


subsample_var2<-subset(subsample2, select=c(knowledge_post, seen_logo, chances, importance_self, appreciate, difference, discuss_online, discuss_real, protest, assignment, compliance, civic, fbtreat, fbvsnewsletter, stream, townpoplog, age_re, sex_2, uni, edu_5, status_per, status_5, friends_re, fbfriends_re, frequency_fb, news_2, news_3, civic_re, environment_act_2, vote_re, scale_trust, role_2, role_3, knowledgescale, nature_re, danger, adventure, pleasure, ability))

subsample_var2$fbcomply[subsample_var2$assignment==1] <- 0
subsample_var2$fbcomply[subsample_var2$assignment==2 & subsample_var2$compliance==1] <- 1
subsample_var2$fbcomply[subsample_var2$assignment==2 & subsample_var2$compliance==0] <- 0
subsample_var2$fbcomply[subsample_var2$assignment==3 & subsample_var2$compliance==0] <- 0
subsample_var2$fbcomply[subsample_var2$assignment==3 & subsample_var2$compliance==1] <- 0

table(subsample_var2$compliance[subsample_var2$assignment!=2])
table(subsample_var2$compliance[subsample_var2$assignment!=3])

subsample_var2$fbtreat[subsample_var2$assignment==1] <- 0
subsample_var2$fbtreat[subsample_var2$assignment==2] <- 1
subsample_var2$fbtreat[subsample_var2$assignment==3] <- 0

subsample_var2$newsletter[subsample_var2$assignment==1] <- 0
subsample_var2$newsletter[subsample_var2$assignment==2] <- 0
subsample_var2$newsletter[subsample_var2$assignment==3] <- 1

subsample_var2$newscomply[subsample_var2$assignment==1] <- 0
subsample_var2$newscomply[subsample_var2$assignment==2 & subsample_var2$compliance==1] <- 0
subsample_var2$newscomply[subsample_var2$assignment==2 & subsample_var2$compliance==0] <- 0
subsample_var2$newscomply[subsample_var2$assignment==3 & subsample_var2$compliance==0] <- 0
subsample_var2$newscomply[subsample_var2$assignment==3 & subsample_var2$compliance==1] <- 1

#Discuss Online

subsample_discuss_online<-subset(subsample_var2,!is.na(discuss_online))

subsample_discuss_online$sdY<-sd(subsample_discuss_online$discuss_online[subsample_discuss_online$assignment==1])
subsample_discuss_online$muY<-mean(subsample_discuss_online$discuss_online[subsample_discuss_online$assignment==1])
subsample_discuss_online$Y <- subsample_discuss_online$discuss_online 

subsample_discuss_online$Yscaled <- (subsample_discuss_online$Y-subsample_discuss_online$muY)/subsample_discuss_online$sdY # define Outcome

subsample_discuss_online$Z <- subsample_discuss_online$assignment # define Treatment Assignment
subsample_discuss_online$X<- as.matrix(subsample_discuss_online[,16:39])
subsample_discuss_online$Z1 <- subsample_discuss_online$fbtreat # define Treatment FB Assignment
subsample_discuss_online$Z2 <- subsample_discuss_online$newsletter # define Treatment Newsletter Assignment
subsample_discuss_online$D1 <- subsample_discuss_online$fbcomply # define Compliance
subsample_discuss_online$D2 <- subsample_discuss_online$newscomply # define Compliance

subsample_discuss_online$blocks[subsample_discuss_online$stream=="representative"] <-0
subsample_discuss_online$blocks[subsample_discuss_online$stream=="activists"] <-1 

subsample_discuss_online_CACEfb<- subset(subsample_discuss_online,!is.na(Z1))
subsample_discuss_online_CACEnl<- subset(subsample_discuss_online,!is.na(Z2))

Z<-subsample_discuss_online$Z

blocks<-subsample_discuss_online$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(117,92, 122),
                      c(64, 57, 48))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_discuss_online$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

subsample_discuss_online_CACEfb<- subset(subsample_discuss_online,!is.na(Z1))
subsample_discuss_online_CACEnl<- subset(subsample_discuss_online,!is.na(Z2))


#Discuss Offline

subsample_discuss_real<-subset(subsample_var2,!is.na(discuss_real))

subsample_discuss_real$Y <- subsample_discuss_real$discuss_real  # define Outcome

subsample_discuss_real$sdY<-sd(subsample_discuss_real$discuss_real[subsample_discuss_real$assignment==1])
subsample_discuss_real$muY<-mean(subsample_discuss_real$discuss_real[subsample_discuss_real$assignment==1])

subsample_discuss_real$Yscaled <- (subsample_discuss_real$discuss_real-subsample_discuss_real$muY)/subsample_discuss_real$sdY # define Outcome

subsample_discuss_real$Z <- subsample_discuss_real$assignment # define Treatment Assignment
subsample_discuss_real$Z1 <- subsample_discuss_real$fbtreat # define Treatment FB Assignment
subsample_discuss_real$Z2 <- subsample_discuss_real$newsletter # define Treatment Newsletter Assignment
subsample_discuss_real$D1 <- subsample_discuss_real$fbcomply # define Compliance
subsample_discuss_real$D2 <- subsample_discuss_real$newscomply # define Compliance
subsample_discuss_real$X<- as.matrix(subsample_discuss_real[,16:39])

subsample_discuss_real$blocks[subsample_discuss_real$stream=="representative"] <-0
subsample_discuss_real$blocks[subsample_discuss_real$stream=="activists"] <-1


Z<-subsample_discuss_real$Z

blocks<-subsample_discuss_real$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(132,106, 145),
                      c(66, 60, 50))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_discuss_real$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

subsample_discuss_real_CACEfb<- subset(subsample_discuss_real,!is.na(Z1))
subsample_discuss_real_CACEnl<- subset(subsample_discuss_real,!is.na(Z2))


#Others Appreciate 

subsample_appreciate<-subset(subsample_var2,!is.na(appreciate))

subsample_appreciate$sdY<-sd(subsample_appreciate$appreciate[subsample_appreciate$assignment==1])
subsample_appreciate$muY<-mean(subsample_appreciate$appreciate[subsample_appreciate$assignment==1])
subsample_appreciate$Y <- subsample_appreciate$appreciate 
subsample_appreciate$Yscaled <- (subsample_appreciate$Y-subsample_appreciate$muY)/subsample_appreciate$sdY # define Outcome

subsample_appreciate$Z <- subsample_appreciate$assignment # define Treatment Assignment
subsample_appreciate$Z1 <- subsample_appreciate$fbtreat # define FB Treatment Assignment
subsample_appreciate$Z2 <- subsample_appreciate$newsletter # define Newsletter Treatment Assignment
subsample_appreciate$D1 <- subsample_appreciate$fbcomply # define Compliance
subsample_appreciate$D2 <- subsample_appreciate$newscomply # define Compliance
subsample_appreciate$X<- as.matrix(subsample_appreciate[,16:39])

subsample_appreciate$blocks[subsample_appreciate$stream=="representative"] <-0
subsample_appreciate$blocks[subsample_appreciate$stream=="activists"] <-1

Z<-subsample_appreciate$Z

blocks<-subsample_appreciate$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(133,108, 146),
                      c(66, 60, 49))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_appreciate$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)


subsample_appreciate_CACEfb<- subset(subsample_appreciate,!is.na(Z1))
subsample_appreciate_CACEnl<- subset(subsample_appreciate,!is.na(Z2))



#Chances

subsample_chances<-subset(subsample_var2,!is.na(chances))

subsample_chances$sdY<-sd(subsample_chances$chances[subsample_chances$assignment==1])
subsample_chances$muY<-mean(subsample_chances$chances[subsample_chances$assignment==1])
subsample_chances$Y <- subsample_chances$chances 
subsample_chances$Yscaled <- (subsample_chances$Y-subsample_chances$muY)/subsample_chances$sdY # define Outcome


subsample_chances$Z <- subsample_chances$assignment # define Treatment Assignment
subsample_chances$Z1 <- subsample_chances$fbtreat # define FB Treatment Assignment
subsample_chances$Z2 <- subsample_chances$newsletter # define Newsletter Treatment Assignment
subsample_chances$D1 <- subsample_chances$fbcomply # define Compliance
subsample_chances$D2 <- subsample_chances$newscomply # define Compliance
subsample_chances$X<- as.matrix(subsample_chances[,16:39])

subsample_chances$blocks[subsample_chances$stream=="representative"] <-0
subsample_chances$blocks[subsample_chances$stream=="activists"] <-1

Z<-subsample_chances$Z

blocks<-subsample_chances$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(133,109, 147),
                      c(67, 61, 50))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_chances$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

subsample_chances_CACEfb<- subset(subsample_chances,!is.na(Z1))
subsample_chances_CACEnl<- subset(subsample_chances,!is.na(Z2))


#Difference

subsample_difference<-subset(subsample_var2,!is.na(difference))

subsample_difference$sdY<-sd(subsample_difference$difference[subsample_difference$assignment==1])
subsample_difference$muY<-mean(subsample_difference$difference[subsample_difference$assignment==1])
subsample_difference$Y <- subsample_difference$difference
subsample_difference$Yscaled <- (subsample_difference$Y-subsample_difference$muY)/subsample_difference$sdY # define Outcome

subsample_difference$Z <- subsample_difference$assignment# define Treatment Assignment
subsample_difference$Z1 <- subsample_difference$fbtreat # define FB Treatment Assignment
subsample_difference$Z2 <- subsample_difference$newsletter # define Newsletter Treatment Assignment
subsample_difference$D1 <- subsample_difference$fbcomply # define Compliance
subsample_difference$D2 <- subsample_difference$newscomply # define Compliance
subsample_difference$X<- as.matrix(subsample_difference[,16:39])

subsample_difference$blocks[subsample_difference$stream=="representative"] <-0
subsample_difference$blocks[subsample_difference$stream=="activists"] <-1

Z<-subsample_difference$Z

blocks<-subsample_difference$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(133,108, 147),
                      c(67, 60, 50))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_difference$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)


subsample_difference_CACEfb<- subset(subsample_difference,!is.na(Z1))
subsample_difference_CACEnl<- subset(subsample_difference,!is.na(Z2))


#Importance Environment

subsample_importance<-subset(subsample_var2,!is.na(importance_self))

subsample_importance$sdY<-sd(subsample_importance$importance_self[subsample_importance$assignment==1])
subsample_importance$muY<-mean(subsample_importance$importance_self[subsample_importance$assignment==1])
subsample_importance$Y <- subsample_importance$importance_self 
subsample_importance$Yscaled <- (subsample_importance$Y-subsample_importance$muY)/subsample_importance$sdY # define Outcome

subsample_importance$Z <- subsample_importance$assignment # define Treatment Assignment
subsample_importance$Z1 <- subsample_importance$fbtreat # define FB Treatment Assignment
subsample_importance$Z2 <- subsample_importance$newsletter # define Newsletter Treatment Assignment
subsample_importance$D1 <- subsample_importance$fbcomply # define Compliance
subsample_importance$D2 <- subsample_importance$newscomply # Compliance
subsample_importance$X<- as.matrix(subsample_importance[,16:39])

subsample_importance$blocks[subsample_importance$stream=="representative"] <-0
subsample_importance$blocks[subsample_importance$stream=="activists"] <-1

Z<-subsample_importance$Z

blocks<-subsample_importance$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(132,106, 143),
                      c(66, 60, 48))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_importance$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

subsample_importance_CACEfb<- subset(subsample_importance,!is.na(Z1))
subsample_importance_CACEnl<- subset(subsample_importance,!is.na(Z2))



#Knowledge

subsample_knowledge<-subset(subsample_var2,!is.na(knowledge_post))

subsample_knowledge$sdY<-sd(subsample_knowledge$knowledge_post[subsample_knowledge$assignment==1] )
subsample_knowledge$muY<-mean(subsample_knowledge$knowledge_post[subsample_knowledge$assignment==1])
subsample_knowledge$Y <- subsample_knowledge$knowledge_post  
subsample_knowledge$Yscaled <- (subsample_knowledge$Y-subsample_knowledge$muY)/subsample_knowledge$sdY # define Outcome

subsample_knowledge$Z <- subsample_knowledge$assignment# define Treatment Assignment
subsample_knowledge$Z1 <- subsample_knowledge$fbtreat # define FB Treatment Assignment
subsample_knowledge$Z2 <- subsample_knowledge$newsletter # define Newsletter Treatment Assignment
subsample_knowledge$D1 <- subsample_knowledge$fbcomply # define Compliance
subsample_knowledge$D2 <- subsample_knowledge$newscomply # define Compliance
subsample_knowledge$X<- as.matrix(subsample_knowledge[,16:39])

subsample_knowledge$blocks[subsample_knowledge$stream=="representative"] <-0
subsample_knowledge$blocks[subsample_knowledge$stream=="activists"] <-1

Z<-subsample_knowledge$Z

blocks<-subsample_knowledge$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(133,108, 147),
                      c(67, 60, 50))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_knowledge$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)


subsample_knowledge_CACEfb<- subset(subsample_knowledge,!is.na(Z1))
subsample_knowledge_CACEnl<- subset(subsample_knowledge,!is.na(Z2))



#Protest

subsample_protest<-subset(subsample_var2,!is.na(protest))

subsample_protest$Y <- subsample_protest$protest  
subsample_protest$sdY<-sd(subsample_protest$protest[subsample_protest$assignment==1] )
subsample_protest$muY<-mean(subsample_protest$protest[subsample_protest$assignment==1])
subsample_protest$Yscaled <- (subsample_protest$Y-subsample_protest$muY)/subsample_protest$sdY # define Outcome

subsample_protest$Z <- subsample_protest$assignment# define Treatment Assignment
subsample_protest$Z1 <- subsample_protest$fbtreat # define FB Treatment Assignment
subsample_protest$Z2 <- subsample_protest$newsletter # define Newsletter Treatment Assignment
subsample_protest$D1 <- subsample_protest$fbcomply # define Compliance
subsample_protest$D2 <- subsample_protest$newscomply # define Compliance
subsample_protest$X<- as.matrix(subsample_protest[,16:39])

subsample_protest$blocks[subsample_protest$stream=="representative"] <-0
subsample_protest$blocks[subsample_protest$stream=="activists"] <-1

Z<-subsample_protest$Z

blocks<-subsample_protest$blocks

assignment<-NA
assignment[Z==1]<-"T1"
assignment[Z==2]<-"T2"
assignment[Z==3]<-"T3"

table(blocks, assignment)

block_m_each <- rbind(c(133,106, 146),
                      c(67, 60, 50))

Blocked_design <- declare_ra(blocks=blocks, block_m_each=block_m_each)
subsample_protest$prob_obs <- obtain_condition_probabilities(Blocked_design, assignment=assignment)

subsample_protest_CACEfb<- subset(subsample_protest,!is.na(Z1))
subsample_protest_CACEnl<- subset(subsample_protest,!is.na(Z2))


#ITT

lm_discussonline_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_discuss_online)

lm_discussonline_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_discuss_online)

lm_discussonline_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_discuss_online)

lm_discussonline_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_discuss_online)

lm_discussoffline_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_discuss_real)

lm_discussoffline_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_discuss_real)

lm_discussoffline_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_discuss_real)

lm_discussoffline_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_discuss_real)

lm_appreciate_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs,data=subsample_appreciate)

lm_appreciate_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs,data=subsample_appreciate)

lm_appreciate_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_appreciate)

lm_appreciate_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_appreciate)

lm_chances_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_chances)

lm_chances_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_chances)

lm_chances_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_chances)

lm_chances_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_chances)

lm_protest_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_protest)

lm_protest_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_protest)

lm_protest_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_protest)

lm_protest_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_protest)

lm_difference_unadj_tab <- lm(Yscaled~factor(Z) , weight=1/prob_obs, data=subsample_difference)

lm_difference_adj_tab <- lm(Yscaled~factor(Z) + X  , weight=1/prob_obs, data=subsample_difference)

lm_difference_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_difference)

lm_difference_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_difference)

lm_importance_unadj_tab <- lm(Yscaled~factor(Z), weight=1/prob_obs,data=subsample_importance)

lm_importance_adj_tab <- lm(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_importance)

lm_importance_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_importance)

lm_importance_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_importance)

lm_knowledge_unadj_tab <- lm(Yscaled~factor(Z),  weight=1/prob_obs,data=subsample_knowledge)

lm_knowledge_adj_tab <- lm(Yscaled~factor(Z) + X,  weight=1/prob_obs,data=subsample_knowledge)

lm_knowledge_unadj <- lm_robust(Yscaled~factor(Z), weight=1/prob_obs, data=subsample_knowledge)

lm_knowledge_adj <- lm_robust(Yscaled~factor(Z) + X, weight=1/prob_obs, data=subsample_knowledge)


#CACE

CACE_discussonline_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_discuss_online)

CACE_discussonline_adj <- iv_robust(Yscaled ~ D1 + D2 + X | Z1 + Z2+ X, weight=1/prob_obs, data=subsample_discuss_online)


CACE_discussonline_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_discuss_online)

CACE_discussonline_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X | Z1 + Z2+ X, weight=1/prob_obs, data=subsample_discuss_online)


CACE_discussoffline_unadj <- iv_robust(Yscaled ~ D1 + D2 | Z1 + Z2, weight=1/prob_obs, data=subsample_discuss_real)

CACE_discussoffline_adj <- iv_robust(Yscaled ~ D1 + D2 + X | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_discuss_real)


CACE_discussoffline_unadj_tab <- ivreg(Yscaled ~ D1 + D2 | Z1 + Z2, weight=1/prob_obs, data=subsample_discuss_real)

CACE_discussoffline_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_discuss_real)


CACE_appreciate_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_appreciate)

CACE_appreciate_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_appreciate)

CACE_appreciate_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_appreciate)

CACE_appreciate_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_appreciate)


CACE_chances_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_chances)

CACE_chances_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_chances)


CACE_chances_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_chances)

CACE_chances_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_chances)


CACE_protest_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_protest)

CACE_protest_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_protest)


CACE_protest_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_protest)

CACE_protest_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_protest)


CACE_difference_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_difference)

CACE_difference_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_difference)


CACE_difference_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_difference)

CACE_difference_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_difference)


CACE_difference_unadj_fb_tab <- ivreg(Yscaled ~ D1  | Z1 , weight=1/prob_obs, data=subsample_difference)

CACE_difference_unadj_nl_tab <- ivreg(Yscaled ~ D2 | Z2 , weight=1/prob_obs, data=subsample_difference)


CACE_difference_adj_fb_tab <- ivreg(Yscaled ~ D1 + X | Z1 + X , weight=1/prob_obs, data=subsample_difference)

CACE_difference_adj_nl_tab <- ivreg(Yscaled ~ D2 + X | Z2 + X , weight=1/prob_obs, data=subsample_difference)


CACE_importance_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_importance)

CACE_importance_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_importance)


CACE_importance_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_importance)

CACE_importance_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_importance)


CACE_knowledge_unadj <- iv_robust(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_knowledge)

CACE_knowledge_adj <- iv_robust(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_knowledge)


CACE_knowledge_unadj_tab <- ivreg(Yscaled ~ D1 + D2  | Z1 + Z2, weight=1/prob_obs, data=subsample_knowledge)

CACE_knowledge_adj_tab <- ivreg(Yscaled ~ D1 + D2 + X  | Z1 + Z2 + X, weight=1/prob_obs, data=subsample_knowledge)


#Table A5

#ITT unadjusted

Tablea5a<-stargazer(lm_discussoffline_unadj_tab, lm_discussonline_unadj_tab, lm_appreciate_unadj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Discussion Offline", "Discussion Online", "Appreciated"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(lm_discussoffline_unadj, lm_discussonline_unadj, lm_appreciate_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci =TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="sidewaystable",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )

#ITT covariate-adjusted

Tablea5b<-stargazer(lm_discussoffline_adj_tab, lm_discussonline_adj_tab, lm_appreciate_adj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Discussion Offline", "Discussion Online", "Appreciated"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(lm_discussoffline_adj, lm_discussoffline_adj, lm_appreciate_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="sidewaystable",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#CACE unadjusted

Tablea5c<-stargazer(CACE_discussoffline_unadj_tab, CACE_discussonline_unadj_tab, CACE_appreciate_unadj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Discussion Offline", "Discussion Online", "Appreciated"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(CACE_discussoffline_unadj, CACE_discussonline_unadj, CACE_appreciate_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="sidewaystable",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#CACE covariate-adjusted

Tablea5d<-stargazer(CACE_discussoffline_adj_tab, CACE_discussonline_adj_tab, CACE_appreciate_adj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Discussion Offline", "Discussion Online", "Appreciated"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(CACE_discussoffline_adj, CACE_discussonline_adj, CACE_appreciate_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="sidewaystable",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#Table A6

#ITT unadjusted

Tablea6a<-stargazer(lm_chances_unadj_tab, lm_difference_unadj_tab, lm_protest_unadj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Chances", "Difference", "Protest"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(lm_chances_unadj, lm_difference_unadj, lm_protest_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )

#ITT covariate-adjusted

Tablea6b<-stargazer(lm_chances_adj_tab, lm_difference_adj_tab, lm_protest_adj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Chances", "Difference", "Protest"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(lm_chances_adj, lm_difference_adj, lm_protest_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#CACE unadjusted

Tablea6c<-stargazer(CACE_chances_unadj_tab, CACE_difference_unadj_tab, CACE_protest_unadj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Chances", "Difference", "Protest"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(CACE_chances_unadj, CACE_difference_unadj, CACE_protest_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )

#CACE covariate-adjusted

Tablea6d<-stargazer(CACE_chances_adj_tab, CACE_difference_adj_tab, CACE_protest_adj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Chances", "Difference", "Protest"), column.separate=c(1,1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL,se = starprep(CACE_chances_adj, CACE_difference_adj, CACE_protest_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )


#Table A7

#ITT unadjusted

Tablea7a<-stargazer(lm_importance_unadj_tab, lm_knowledge_unadj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Importance", "Knowledge"), column.separate=c(1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL, se = starprep(lm_importance_unadj, lm_knowledge_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )

#ITT covariate-adjusted

Tablea7b<-stargazer(lm_importance_adj_tab, lm_knowledge_adj_tab,
          type = "latex", title ="Linear Regression Results (ITT)", style = "ajps",
          column.labels=c("Importance", "Knowledge"), column.separate=c(1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL,  se = starprep(lm_importance_adj, lm_knowledge_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )



#CACE unadjusted

Tablea7c<-stargazer(CACE_importance_unadj_tab, CACE_knowledge_unadj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Importance", "Knowledge"), column.separate=c(1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL,  se = starprep(CACE_importance_unadj, CACE_knowledge_unadj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )



#CACE covariate-adjusted


Tablea7d<-stargazer(CACE_importance_adj_tab, CACE_knowledge_adj_tab,
          type = "latex", title ="Complier Average Causal Effect (CACE)", style = "ajps",
          column.labels=c("Importance", "Knowledge"), column.separate=c(1,1),
          dep.var.caption = NULL,
          dep.var.labels.include = TRUE,
          covariate.labels = c("Facebook", "Newsletter"), 
          align = FALSE,
          coef = NULL,  se = starprep(CACE_importance_adj, CACE_knowledge_adj), t = NULL, p = NULL,
          t.auto = TRUE, p.auto = TRUE,
          ci = TRUE, ci.custom = NULL,
          ci.level = 0.95, ci.separator = NULL,
          add.lines = NULL,
          apply.coef = NULL, apply.se = NULL,
          apply.t = NULL, apply.p = NULL, apply.ci = NULL,
          colnames = NULL,
          column.sep.width = "5pt",
          decimal.mark = NULL, df = TRUE,
          digit.separate = NULL, digit.separator = NULL,
          digits = NULL, digits.extra = NULL, flip = TRUE,
          float = TRUE, float.env="table",
          font.size = NULL, header = TRUE,
          initial.zero = NULL,
          intercept.bottom = FALSE, intercept.top = FALSE,
          keep = NULL, keep.stat = NULL, model.names = FALSE,
          model.numbers = FALSE, multicolumn = TRUE,
          no.space = NULL,
          notes = NULL, notes.align = NULL,
          notes.append = TRUE, notes.label = NULL,
          object.names = FALSE,
          omit = c("X", "Constant", "blocks"), omit.labels = NULL,
          omit.stat = NULL, omit.summary.stat = NULL,
          omit.table.layout = NULL,
          omit.yes.no = c("Yes", "No"),
          order = NULL, ord.intercepts = FALSE,
          perl = FALSE, report = NULL, rownames = NULL,
          rq.se = "nid", selection.equation = FALSE,
          single.row = FALSE,
          star.char = NULL, star.cutoffs = NULL,
          suppress.errors = FALSE,
          table.layout = NULL, table.placement = "!",
          zero.component = FALSE,
          summary.logical = TRUE, summary.stat = NULL,
          nobs = TRUE, mean.sd = TRUE, min.max = TRUE,
          median = FALSE, iqr = FALSE )

sink("tables_OA.txt")

print(tab_power)

print(tab_balance)

print(Tablea4)

print(Tablea5a)

print(Tablea5b)

print(Tablea5c)

print(Tablea5d)

print(Tablea6a)

print(Tablea6b)

print(Tablea6c)

print(Tablea6d)

print(Tablea7a)

print(Tablea7b)

print(Tablea7c)

print(Tablea7d)

print(sIOA, RNG = TRUE, locale = FALSE)

sink()
